package com.javaoopfour.util;

import com.javaoopfour.Menus;

public class PageUtil<T> {

    private int pageCuree=1; //页码-->起始行数
    private int limit=2; //总记录行数

    //计算总页数
    public int getCount(T[] obj){
        //todo 计算总数

        return obj.length;
    }

    //上一页
    public Menus[] upPage(int curePage,int limit, T[] obj){

        //todo 根据页码计算出，当前页码所对应的条数、
        int index=(curePage-1)*limit;
        if(curePage<1){
            return new Menus[10];
        }

        Menus[] ts = new Menus[10];
        //todo 根据页码计算出，当前页码所对应的条数、1,2
        for (int i = index; i <(curePage*limit) ; i++) {
            Menus t = (Menus)obj[i];
            ts[i]=t;
        }
        return ts;
    }

    //下一页
    public Menus[] nextPage(int curePage,int limit, T[] obj){
        //todo 根据页码计算出，当前页码所对应的条数、
        int index=(curePage-1)*limit;

        //最大页码
        int ceil = (int) Math.ceil(obj.length / limit);
        if(curePage>ceil){
            return new Menus[10];
        }

        Menus[] ts = new Menus[10];
        //todo 根据页码计算出，当前页码所对应的条数、1,2
        for (int i = index; i <(curePage*limit) ; i++) {
            Menus t = (Menus)obj[i];
            ts[i]=t;
        }
        return ts;
    }

    public int getPageCuree() {
        return pageCuree;
    }

    public void setPageCuree(int pageCuree) {
        this.pageCuree = pageCuree;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }
}
